package ar.edu.itba.tp1.gps.heuristics;

import java.util.List;

import ar.edu.itba.tp1.gps.GPSRun;
import ar.edu.itba.tp1.gps.api.GPSProblemImpl;
import ar.edu.itba.tp1.gps.api.GPSState;
import ar.edu.itba.tp1.gps.board.ArithmeticsRestrictions;
import ar.edu.itba.tp1.gps.board.Bucket;
import ar.edu.itba.tp1.gps.board.Coordinate;

public class GPSProblemFirstHeuristic extends GPSProblemImpl {
	private ArithmeticsRestrictions restrictions;
	
	public GPSProblemFirstHeuristic(ArithmeticsRestrictions restrictions) {
		super(restrictions);
		this.restrictions = restrictions;
	}
	
	@Override
	public Integer getHValue(GPSState state) {
		List<Bucket> buckets = restrictions.getBoardRestictions();
		int completeBuckets = 0;

		for (Bucket bucket : buckets) {
			int cantCells = 0;
			List<Coordinate> groupCells = bucket.getGroupCells();
			for (Coordinate cell : groupCells) {
				if (state.getValues()[cell.getX()][cell.getY()] != null) {
					cantCells++;
				}
			}
			if (cantCells == groupCells.size()){
				completeBuckets++;
			}
		}
		return (buckets.size() - completeBuckets)*((GPSRun.n * GPSRun.n) / buckets.size() + 1);
	}
	
}
